package com.itheima.dao;

import com.itheima.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserDao {
    @Results({
            @Result(column = "id" , property = "id"),
            @Result(column = "name" , property = "name"),
            @Result(column = "gender" , property = "gender"),
            @Result(column = "age" , property = "age"),
            @Result(column = "address" , property = "address"),
            @Result(column = "qq" , property = "qq"),
            @Result(column = "email" , property = "email"),
            @Result(column = "id" , property = "id"),
    })
    @Select(" select * from user")
    List<User> findAll();
    @Insert("insert into user values(null,#{name},#{gender},#{age},#{address},#{qq},#{email},null,null)")
    void save(User user);
   @Delete("delete from user where id=#{id}")
    void deleteById(String id);
    @Select("select * from user  where id=#{id}")
    User findById(String id);
    @Update("update user set name = #{name},gender = #{gender} ,age = #{age} , address = #{address} , qq = #{qq}, email = #{email} where id = #{id}")
    void update(User user);
    @Select("select * from user where username=#{username} and password=#{password}")
    User login(@Param("username") String username, @Param("password") String password);
    //delete from user where id in(105,106,107)
    @Delete("<script>delete from user" +
            "<where>" +
            "<foreach  collection='array' open='id in(' close=')' separator=',' item='id'>#{id}</foreach>" +
            "</where>" +
            "</script>")

    void deleteAll(String[] ids);
@Select("select count(*) from user where name=#{name}")
    int findByName(String name);
/*    @Select("select count(*) from user where name=#{name}")
    int findByName(String name);*/
/*
    @Select( " <script>" +
            " select id, user_id userId, batch_number batchNumber, unit_name unitName, word_detail wordDetail,word, score, create_time createTime " +
            " from word_practice_records where user_id =#{userId} and batch_number=#{batchNumber} and unit_name=#{unitName} and  word  in "+
            " <foreach collection='wordScoreViewList' open='(' item='wordScore' separator=',' close=')'> #{wordScore.word}</foreach> "+
            " </script>" )

 //  collection 遍历的类型,(集合为list,数组为array,如果方法参数是对象的某个属性,而这个属性是list,或array类型,就可以写形参的名字)
 //  open 条件的开始
 //  close 条件的结束
 //  item  遍历集合时候定义的临时变量，存储当前遍历的每一个值
 //  separator 多个值之间用逗号拼接
    //   #{wordScore.word} 获取遍历的每一个值,与item定义的临时变量一致，item变量是一个实体，要获取里面word属性*/






}
